﻿using FacebookWrapper;
using FacebookWrapper.ObjectModel;

namespace Desktop_Facebook
{
    public delegate void LoginEventHandler(object sender, LoginEventArgs e);

    internal class Session
    {
        private static Session m_Instance = null;

        public static Session Instance
        {
            get
            {
                if (m_Instance == null)
                {
                    m_Instance = new Session();
                }

                return m_Instance;
            }
        }

        public User LoggedInUser { get; set; }

        public event LoginEventHandler LoggedIn;

		public LoginResult LoginResult { get; set; }

		private Session() 
        { 
        }

        public void Login()
        {
			LoginResult = FacebookService.Login(
				"337106723005201", 
				"read_mailbox", 
				"friends_birthday", 
				"email", 
				"user_events", 
				"read_stream", 
				"user_likes", 
				"friends_likes");

			if (string.IsNullOrEmpty(LoginResult.ErrorMessage))
            {
				LoggedInUser = LoginResult.LoggedInUser;
            }

            if (LoggedIn != null)
            {
				LoggedIn.Invoke(this, new LoginEventArgs { Result = LoginResult });
            }
        }
    }
}
